package com.zte.cl.utils;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 自定义RejectedExecutionHandler， 当线程任务被拒绝时，使其等待线程管理池空余后继续被调用
 * 
 * @author Zjq
 * 
 */
public class RejectedExcutionHandlerImpl implements RejectedExecutionHandler {
	
	private static final Log log = LogFactory.getLog(RejectedExcutionHandlerImpl.class);
	
	@Override
	public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
		if (!executor.isShutdown()) {
			try {
				log.debug("把任务加入线程池队列");
				executor.getQueue().put(r);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
